package net.xxcl.kygl.service;

import java.util.List;
import net.xxcl.kygl.mapper.SubjectMapper;
import net.xxcl.kygl.pojo.Criteria;
import net.xxcl.kygl.pojo.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional()
public class SubjectService {
    @Autowired
    private SubjectMapper subjectMapper;

    private static final Logger logger = LoggerFactory.getLogger(SubjectService.class);

    public int countByExample(Criteria example) {
        int count = this.subjectMapper.countByExample(example);
        logger.debug("count: {}", count);
        return count;
    }

    public Subject selectByPrimaryKey(Integer id) {
        return this.subjectMapper.selectByPrimaryKey(id);
    }

    public List<Subject> selectByExample(Criteria example) {
        return this.subjectMapper.selectByExample(example);
    }

    public int deleteByPrimaryKey(Integer id) {
        return this.subjectMapper.deleteByPrimaryKey(id);
    }

    public int updateByPrimaryKeySelective(Subject record) {
        return this.subjectMapper.updateByPrimaryKeySelective(record);
    }

    public int updateByPrimaryKey(Subject record) {
        return this.subjectMapper.updateByPrimaryKey(record);
    }

    public int deleteByExample(Criteria example) {
        return this.subjectMapper.deleteByExample(example);
    }

    public int updateByExampleSelective(Subject record, Criteria example) {
        return this.subjectMapper.updateByExampleSelective(record, example);
    }

    public int updateByExample(Subject record, Criteria example) {
        return this.subjectMapper.updateByExample(record, example);
    }

    public int insert(Subject record) {
        return this.subjectMapper.insert(record);
    }

    public int insertSelective(Subject record) {
        return this.subjectMapper.insertSelective(record);
    }

    /**
     * 删除学科组
     * @param ids
     * @return
     */
    public int deleteSubjects(String ids) {
        String[] str = ids.split(",");
        for(String id:str){
            this.subjectMapper.deleteByPrimaryKey(Integer.parseInt(id));
        }
        return str.length;
    }
}